/*    */ package com.zimbra.cs.account.callback;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AttributeCallback;
/*    */ import com.zimbra.cs.account.AttributeCallback.SingleValueMod;
/*    */ import com.zimbra.cs.account.Entry;
/*    */ import com.zimbra.cs.account.Identity;
/*    */ import com.zimbra.cs.account.Signature;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class MailSignature
/*    */   extends AttributeCallback
/*    */ {
/*    */   public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry)
/*    */     throws ServiceException
/*    */   {
/* 42 */     AttributeCallback.SingleValueMod mod = singleValueMod(attrName, value);
/* 43 */     if (mod.unsetting()) {
/* 44 */       return;
/*    */     }
/* 46 */     if ((entry != null) && (!(entry instanceof Account)) && (!(entry instanceof Identity)) && (!(entry instanceof Signature)))
/*    */     {
/* 48 */       return;
/*    */     }
/*    */     
/* 51 */     long maxLen = -1L;
/*    */     
/* 53 */     String maxInContext = context.getData(CallbackContext.DataKey.MAX_SIGNATURE_LEN);
/* 54 */     if (maxInContext != null) {
/*    */       try {
/* 56 */         maxLen = Integer.parseInt(maxInContext);
/*    */       } catch (NumberFormatException e) {
/* 58 */         ZimbraLog.account.warn("encountered invalid " + CallbackContext.DataKey.MAX_SIGNATURE_LEN.name() + ": " + maxInContext);
/*    */       }
/*    */     }
/*    */     
/*    */ 
/* 63 */     if (maxLen == -1L) {
/* 64 */       String maxInAttrsToModify = (String)attrsToModify.get("zimbraMailSignatureMaxLength");
/* 65 */       if (maxInAttrsToModify != null) {
/*    */         try {
/* 67 */           maxLen = Integer.parseInt(maxInAttrsToModify);
/*    */         } catch (NumberFormatException e) {
/* 69 */           ZimbraLog.account.warn("encountered invalid zimbraMailSignatureMaxLength: " + maxInAttrsToModify);
/*    */         }
/*    */       }
/*    */     }
/*    */     
/*    */ 
/*    */ 
/* 76 */     if (maxLen == -1L) {
/* 77 */       if (entry == null) {
/*    */         return;
/*    */       }
/*    */       
/*    */       Account account;
/* 82 */       if ((entry instanceof Account)) {
/* 83 */         account = (Account)entry; } else { Account account;
/* 84 */         if ((entry instanceof Identity)) {
/* 85 */           account = ((Identity)entry).getAccount(); } else { Account account;
/* 86 */           if ((entry instanceof Signature))
/* 87 */             account = ((Signature)entry).getAccount(); else
/*    */             return;
/*    */         }
/*    */       }
/*    */       Account account;
/* 92 */       maxLen = account.getMailSignatureMaxLength();
/*    */     }
/*    */     
/*    */ 
/* 96 */     if ((maxLen != 0L) && (((String)value).length() > maxLen)) {
/* 97 */       throw ServiceException.INVALID_REQUEST("zimbraPrefMailSignature is longer than the limited value " + maxLen, null);
/*    */     }
/*    */   }
/*    */   
/*    */   public void postModify(CallbackContext context, String attrName, Entry entry) {}
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/MailSignature.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */